<?php


namespace App\Service;


use GuzzleHttp\Client;
use Illuminate\Support\Carbon;

class RobotService
{
    public function send($key, $text)
    {
        $client = new Client();
        $result = $client->post('https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=' . $key, [
            'json' => [
                'msgtype' => 'text',
                'text' => [
                    "content" => $text
                ]
            ]
        ]);
        $result = json_decode($result->getBody()->getContents(), true);
        if ($result['errcode'] === 0 && isset($result['errcode'])) {
            \Log::channel('robot')->info('机器人推送成功:'.$key,[$text]);
            return true;
        }
        \Log::channel('robot')->error('机器人推送失败:'.$key.$text,$result);
    }
}
